﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace SpaceMan.Entities.Attachments
{
    abstract class I_Attachment
    {
        Vector2 Position;
        float Rotation;
        Dictionary<string, I_Attachment> Children = new Dictionary<string, I_Attachment>();
        Dictionary<string, Vector2> AttachmentPoints;

        public void BaseInitialize(Dictionary<string, Vector2> AttachmentPoints)
        {
            this.AttachmentPoints = AttachmentPoints;
        }

        
        public void Update(Vector2 Position, float Rotation)
        {
            if (AttachmentPoints != null)
            {
                for (int i = 0; i < AttachmentPoints.Count; i++)
                {
                    if (Children.ContainsKey(AttachmentPoints.ElementAt(i).Key))
                    {
                        Children[AttachmentPoints.ElementAt(i).Key].Update(S_Global.getRotPos(AttachmentPoints[AttachmentPoints.ElementAt(i).Key], Position, Rotation), Rotation);
                    }
                }
            }
        }

        public void AddAttachment(string AttachmentPoint, I_Attachment Attachment)
        {
            if (AttachmentPoints != null)
            {
                if (AttachmentPoints.ContainsKey(AttachmentPoint))
                {
                    if (!Children.ContainsKey(AttachmentPoint))
                    {
                        Children.Add(AttachmentPoint, Attachment);
                    }
                }
            }
        }

        public void RemoveAttachment(string AttachmentPoint)
        {
            if (AttachmentPoints != null)
            {
                if (AttachmentPoint.ToUpper() == "ALL")
                {
                    Children.Clear();
                }

                else
                {
                    if (Children.ContainsKey(AttachmentPoint))
                    {
                        Children.Remove(AttachmentPoint);
                    }
                }
            }
        }
    }
}
